// 该文件存放 page/component 实例（onload执行时生成，setup执行完清空）

// page/component 实例
type PlainObject = Record<string, any>
export type PageInstance = WechatMiniprogram.Page.Instance<Record<string, any>, PlainObject>
export type ComponentInstance = WechatMiniprogram.Component.Instance<
	Record<string, any>,
	Record<string, WechatMiniprogram.Component.AllProperty>,
	Record<string, (...args: any[]) => any>
>
export type CurrentInstance = PageInstance | ComponentInstance

let CurrentInstance: CurrentInstance = null

/** 
 * 存入 page/component 实例
 * @param target {CurrentInstance} page/component 实例
 */
export function setCurrentInstance(target: CurrentInstance): void {
	CurrentInstance = target
}

/** 
 * 获取 page/component 实例
 * @return {CurrentInstance} page/component 实例
 */
export const getCurrentInstance = (): CurrentInstance => CurrentInstance
